let fs = require('fs');
var path = require('path'); //系统路径模块
let components = []
const files = fs.readdirSync('./../../public/img/emoji')
console.log(files);
files.map((item, index) => {
  let name = item.replace(/\.gif$/, '');
  let obj = {
    name: name,
    url: item
  }
  components.push(obj)
});
let str = JSON.stringify(components);
fs.stat('./../json/extension.json', function (err, stats) {
  if (err) {
    console.error(err);
    console.log('生成中...');
    fs.writeFile('./../json/extension.json', str, function (err) {
      if (err) {
        res.status(500).send('Server is error...')
      }
    })
  }

});

// fs.writeFile('./../json/extension.json', str, function (err) {
//   if (err) {
//     res.status(500).send('Server is error...')
//   }
// })
//node file.js